__author__ = 'shawhen'

import threading
import sys


class UThread(threading.Thread):
    def __init__(self, target=None, name=None, daemon=None, eccatcher=None, args=(), kwargs={}):
        super(UThread, self).__init__(target=target, name=name, daemon=daemon, args=args, kwargs=kwargs)

        self._eccatcher = eccatcher

    def run(self):
        try:
            self._target(*self._args, **self._kwargs)
        except Exception as e:
            if self._eccatcher is not None:
                self._eccatcher.exception(sys.exc_info())
            else:
                import traceback
                traceback.print_exc()
        finally:
            del self._target, self._args, self._kwargs